package com.mibao.defense;

import java.util.List;

import android.content.ComponentName;
import android.content.Context;
import android.os.Bundle;

public class DefenseMain {
	Context Ctx;
	List<String> appNameList;
	boolean      isHideFlag  = true;

	public DefenseMain(Context text){
		this.Ctx = text;
	}
	public void HideAppIcon(List<String> HideAppList){
		this.appNameList = HideAppList;
		this.isHideFlag  = true;

		runDefense(Ctx);
	}
	public void CancelHideAppIcon(List<String> DisplayAppList){
		this.appNameList = DisplayAppList;
		this.isHideFlag  = false;

		runDefense(Ctx);
	}
	
	private void runDefense(Context Ctx) {

		IDefenseCallback callback = new IDefenseCallback() {
			List<String> appNameTemp = appNameList;
	        boolean      flag = isHideFlag;
			@Override
			public void onSuccess(Bundle bundle) {
				// TODO Auto-generated method stub
				LogUtil.d("[UI] IDefenseCallback onSuccess");
				for(int i = 0;i < appNameTemp.size();i++){
					String appName = appNameTemp.get(i);
					DefenseHostService.setAppIconHidden(appName, flag); //"com.moji.mjweather"  true 隐藏 ； false 显示
				}				
			}
			
			@Override
			public void onFailure(Bundle bundle) {
				// TODO Auto-generated method stub
				LogUtil.d("[UI] IDefenseCallback onFailure");
			}
		};
		
		IDefenseMonitor monitor = new IDefenseMonitor() {
			List<String> appNameTemp = appNameList;
			@Override
			public boolean onWifiOpenning() {
				// TODO Auto-generated method stub
				return true;
			}
			
			@Override
			public boolean onWifiClosing() {
				// TODO Auto-generated method stub
				return true;
			}
			
			@Override
			public boolean onPackageInstalling(List<String> appLabels) {
				// TODO Auto-generated method stub
				return true;
			}
			
			@Override
			public boolean onPackageDeleting(String packageName) {
				// TODO Auto-generated method stub
				return true;
			}
			
			@Override
			public boolean onGprsOpenning() {
				// TODO Auto-generated method stub
				return true;
			}
			
			@Override
			public boolean onGprsClosing() {
				// TODO Auto-generated method stub
				return true;
			}
			
			@Override
			public boolean onDevicePolicyRemoving(ComponentName policyReceiver) {
				// TODO Auto-generated method stub
				return true;
			}
			
			@Override
			public boolean onBluetoothOpenning() {
				// TODO Auto-generated method stub
				return true;
			}
			
			@Override
			public boolean onBluetoothClosing() {
				// TODO Auto-generated method stub
				return true;
			}
			
			@Override
			public boolean onAppIconDisplaying(String packageName) {
				// TODO Auto-generated method stub
				LogUtil.d("[UI] IDefenseMonitor, onAppIconDisplaying, packageName:" + packageName);
                boolean  tag = false;
				for(int i =0;i<appNameTemp.size();i++){
					if (packageName != null && packageName.equals(appNameTemp.get(i))) {
						tag = false;   //false 隐藏 true 显示
					}
					tag = true;
                }
				return tag;
			}
		};
		DefenseHostService.start(Ctx, callback, monitor); //getApplicationContext()
	}
}
